home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / comm / irc / AVSearch.lha / AVSearch.amirx next >
Encoding:
Text File  |  2000-08-02  |  3.5 KB  |  147 lines

  1. /* Search Altavista thru Amirc or CLI.  © 2000 by PurpleT. Requires HttpResume */
  2. /* $VER V1.1 Bug reports? suggestions? Mailto: purplet@dingoblue.net.au        */
  3.  
  4. /*   P R E F S    A R E A  */
  5.  
  6.  
  7. MaxHits = 3
  8.  
  9. /* Info Fields */
  10.  
  11. ShowDescription  = "Y"    /*    [ Y/N ] */
  12. ShowFileURL      = "Y"    /*    [ Y/N ] */
  13.  
  14. SeparateOutput   = "N"    /*    [ Y/N ] */
  15. DeleteTempAfter  = "Y"    /*    [ Y/N ] */
  16.  
  17. AVSTempFile = "Ram:AVSTemp.html"
  18. HttpResumePath = "C:HttpResume"
  19.  
  20. /*     E N D    P R E F S     */
  21.  
  22.  
  23.  
  24.  
  25. /* Don't Edit Anything Below This Point!! */
  26.  
  27. Options results
  28. parse arg SearchString;NL='0a'x;ES= d2c(27);Bold = d2c(2);TC = 1
  29.  
  30. CheckIt = getclip(AVSearch)
  31.  
  32. If CheckIt = "RUN" then DO
  33.    techo("Search already in progress. Wait for current search to finish.")
  34.    Exit
  35. End
  36.  
  37. Setclip(AVSearch,"RUN")
  38.  
  39. If SearchString = "" then DO
  40.    Techo("Usage: /RX AVSearch <Search Keywords>")
  41.    Call EndProg
  42. End
  43.  
  44. If exists(httpresumepath) = 0 then DO
  45.    Techo("Error: You need HttpResume to use this! :)")
  46.    Call EndProg
  47. End
  48. If MaxHits > 10 then MaxHits = 10
  49. If MaxHits < 1 then MaxHits = 1
  50.  
  51. Techo("Searching for "bold""SearchString""Bold" on AltaVista, MaxHits = "bold""MaxHits""bold", Please wait...")
  52.  
  53. SearchString2 = Translate(SearchString,"+"," ")
  54. If Exists(AVSTempFile) = 1 then Address command "delete >nil: "AVSTempFile
  55. address command httpresumepath' url = "http://www.altavista.com/cgi-bin/query?pg=q&sc=on&hl=on&act=2006&par=0&q='SearchString2'&search.x=21&search.y=6&kl=XX&stype=stext" OF = 'AVSTempFile' Referer = "http://www.altavista.com" >nil:'
  56.  
  57. If Exists(AVSTempFile) = 0 then DO
  58.    Techo("Error: File not found - "AVSTempFile)
  59.    Call EndProg
  60. End
  61.  
  62. Open(File1,AVSTempFile,"R")
  63.  
  64. call time(R)
  65.  
  66. Do i = 1 to MaxHits
  67.    HLine = readln(file1)
  68.    Do until HLine = "<b class=txt2>"i".</b>"
  69.       HLine = ReadLn(File1)
  70.       If Find(HLine,"found no document matching your") ~=0 then DO
  71.          Techo("No matches found for "Bold""SearchString)
  72.          Call EndProg
  73.       End
  74.       If upper(HLine) = "</HTML>" then DO
  75.          Call EndProg
  76.       End
  77.    End
  78.    XT=Readln(File1);XT=Readln(File1)
  79.  
  80.    ULine = Word(Translate(SubStr(Readln(File1),13),"",""">"),1)
  81.    techo(bold""i". "Bold""ULine)
  82.    XT=Readln(File1);XT=Readln(File1)
  83.  
  84.    Description = ReadLn(File1)
  85.    XT=ReadLn(File1);XT=ReadLn(File1)
  86.  
  87.    FileURL = ReadLn(File1) /* ;FileURL = SubStr(Left(FileURL,Length(FileURL)-11),4) */
  88.  
  89.    Desc = Description
  90.  
  91. /* Begin Snorslex's Sheer Coding Brilliance ;-) */
  92.  
  93. amirc_bold='02'x
  94. amirc_uline='1F'x
  95. cr=''x
  96. Tags    ="<B> </B> <U> </U> <BR>"
  97. NewTags ="amirc_bold amirc_bold amirc_uline amirc_uline cr"
  98.  
  99. DO UNTIL Tags=''
  100.  PARSE VAR Tags Tag Tags
  101.  PARSE VAR NewTags NewTag NewTags
  102.  CALL TagCleanup(UPPER(Tag),NewTag)
  103. END
  104.  
  105. /* End Snorslex's Sheer Coding Brilliance ;-) */
  106.  
  107.    Description = Desc
  108.  
  109.    If upper(ShowDescription) = "Y" then Techo(Bold"   "Bold""Description)
  110.    If upper(ShowFileURL) = "Y" then Techo(Bold"   "Bold""FileURL)
  111.    If Upper(SeparateOutput) = "Y" then Techo(Bold""Bold)
  112. End
  113. Call EndProg
  114. Exit
  115.  
  116. EndProg:
  117. Close(File1)
  118. Techo(Bold"Search Complete")
  119. SetClip(AVSearch,"")
  120. If Upper(DeleteTempAfter) = "Y" then DO
  121.    address command 'C:Delete >nil: 'AVSTempFile
  122. End
  123. Exit
  124. Return
  125.  
  126. Techo:
  127. parse arg EchoString
  128. "ECHO P="d2c(27)"b«AVSearch» C="TC" "EchoString
  129. say EchoString
  130. Return 0
  131.  
  132. /* Begin Snorslex's Sheer Coding Brilliance (Part II) :) */
  133.  
  134. TagCleanup: 
  135.  curr_tag=ARG(1)
  136.  curr_newtag=ARG(2)
  137.  DO FOREVER
  138.   posi=POS(curr_tag,UPPER(desc))
  139.   IF posi>0 THEN DO
  140.    desc=LEFT(desc,posi-1)||VALUE(curr_newtag)||SUBSTR(desc,posi+LENGTH(curr_tag),LENGTH(desc)-posi)
  141.   END
  142.   ELSE LEAVE
  143.  END
  144. RETURN
  145.  
  146. /* End Snor... you get the picture :) */
  147.